package hadoop.mr03;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class Free_Mapper extends Mapper<LongWritable, Text,Text,Food_City> {
    Text t1 = new Text();

    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Food_City>.Context context) throws IOException, InterruptedException {
        String[] split = value.toString().split(",");
        String foodName = split[0];
        if(split[2].equals("点评数")==false && foodName.length()>0) {
            int comments = Integer.parseInt(split[2]);
            double taste = Double.parseDouble(split[3]);
            double environment = Double.parseDouble(split[4]);
            double serve = Double.parseDouble(split[5]);
            t1.set(foodName);
            Food_City fc = new Food_City(comments, taste, environment, serve);
            context.write(t1, fc);
        }
    }
}
